package com.Util;


import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dm.model.v20151123.SingleSendMailRequest;
import com.aliyuncs.dm.model.v20151123.SingleSendMailResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

public class MailUtil  {

    public static Boolean mailSend(String address,String subject,String htmlBody) throws Exception {

    IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", Config.ACCESSKEYID, Config.ACCESSKEYSECRET);
    IAcsClient client = new DefaultAcsClient(profile);
    SingleSendMailRequest request = new SingleSendMailRequest();
        request.setAccountName(	"hdjun@dragonjun.com");
        request.setFromAlias("后端君");
        request.setAddressType(1);
        request.setTagName("hdjun");
        request.setReplyToAddress(true);
        request.setToAddress(address);
        request.setSubject(subject);
        request.setHtmlBody("<div style=\"text-align: center\" ><img src=\"http://dragonjun.oss-cn-beijing.aliyuncs.com/mail/thanks.jpg\" alt=\"感谢\"></div>\n" +
                "<div>\n" +
                "    <strong>尊敬的后端君用户：</strong><br>\n" +
                "    　　您好! 就在网站马上成立的时候！有你们参与内测十分感谢!<br>\n" +
                "    　　<span style=\"color: green\">在您的大力支持与关心下，后端君即将上线。您的关心和支持是我们成长的不竭源泉。您的每一次参与、每一个建议，都让我激动不已，促使我不断奋进。我们在未来的发展过程中将面临更多的机遇和挑战，我衷心地希望你们作为我的博客的坚强后盾，一如既往地理解和支持我，共同经历前进道路上的风雨坎坷。有了您，我前进的征途才有源源不绝的信心和力量;有了您，我的事业才能长盛不衰地兴旺和发展在今后的岁月里\n" +
                "    ，希望能够继续得到您的关心和大力支持!客户满意是我永恒的追求，\n" +
                "    我将继续为您提供最真诚的服务最后再一次感谢后端君的信任和支持。</span>\n" +
                "    <h1>【官方邮件！】</h1>\n" +
                "</div>");
            SingleSendMailResponse httpResponse = client.getAcsResponse(request);
            return true;


    }

    /**
     * 发送验证码
     * @param address
     * @param code
     */
    public static void mailSendCode(String address,Integer code) throws Exception{
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", Config.ACCESSKEYID, Config.ACCESSKEYSECRET);
        IAcsClient client = new DefaultAcsClient(profile);
        SingleSendMailRequest request = new SingleSendMailRequest();
        request.setAccountName(	"hdjun@dragonjun.com");
        request.setFromAlias("后端君");
        request.setAddressType(1);
        request.setTagName("hdjun");
        request.setReplyToAddress(true);
        request.setToAddress(address);
        request.setSubject("找回密码");
        request.setHtmlBody("<div style=\"margin-left: 35%\">\n" +
                "<img style=\"vertical-align:middle;margin-left: 35px\" src=\"http://www.dragonjun.com/logo.png\" alt=\"后端君\"><br>\n" +
                "您本次的验证码为 <span style=\"color: red;font-size: 27px\">"+code+"</span> 有效期为15分钟,尽快使用！\n" +
                "</div>");
         client.getAcsResponse(request);

    }

    public static void main(String[] args) {
        try {
            //MailUtil.mailSend ( "1012064404@qq.com","感谢信","" );
            MailUtil.mailSendCode ( "1012064404@qq.com",231313 );
        } catch (Exception e) {
            e.printStackTrace ();
        }
    }
}
